home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / interapplication comm / finderdragpro / fdputilities.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  5.3 KB  |  115 lines

  1. /*
  2.     File:        FDPUtilities.c
  3.     
  4.     Description:     utilities used in FinderDragPro.c.  Routines in this file are used in the
  5.                 FinderDragPro.c file;  however, since they are not directly related
  6.                 to the example, they have been moved here to simplify the main file.
  7.  
  8.     Author:        John Montbriand
  9.  
  10.     Copyright:     Copyright: © 1999 by Apple Computer, Inc.
  11.                 all rights reserved.
  12.     
  13.     Disclaimer:    You may incorporate this sample code into your applications without
  14.                 restriction, though the sample code has been provided "AS IS" and the
  15.                 responsibility for its operation is 100% yours.  However, what you are
  16.                 not permitted to do is to redistribute the source as "DSC Sample Code"
  17.                 after having made changes. If you're going to re-distribute the source,
  18.                 we require that you make it clear in the source that the code was
  19.                 descended from Apple Sample Code, but that you've made changes.
  20.     
  21.     Change History (most recent first):
  22.     9/9/99 created by John Montbriand
  23. */
  24.  
  25. #ifndef __FDPUTILITIES__
  26. #define __FDPUTILITIES__
  27.  
  28. #include <MacTypes.h>
  29. #include <Files.h>
  30. #include <Aliases.h>
  31. #include <Drag.h>
  32. #include <Icons.h>
  33. #include <QDOffscreen.h>
  34. #include <Script.h>
  35.  
  36.  
  37. /* ValidFSSpec verifies that *spec refers is formatted correctly, and it
  38.     verifies that it refers to an existing file in an existing directory on
  39.     and existing volume. If *spec is valid, the function returns noErr,
  40.     otherwise an error is returned. */
  41. OSErr ValidFSSpec(FSSpec *spec);
  42.  
  43.  
  44. /* ResolveAliasQuietly resolves an alias using a fast search with no user interaction.  Our main loop
  45.     periodically resolves gFileAlias comparing the result to gTargetFile to keep the display up to date.
  46.     As a result, we would like the resolve alias call to be as quick as possible AND since the application
  47.     may be in the background when  it is called, we don't want any user interaction. */
  48. OSErr ResolveAliasQuietly(ConstFSSpecPtr fromFile, AliasHandle alias, FSSpec *target, Boolean *wasChanged);
  49.  
  50.  
  51. /* MakeHFSFlavorFromAlias converts an alias handle into a HFSFlavor
  52.     structure filling in the fields with their correct values. */
  53. OSErr MakeHFSFlavorFromAlias(AliasHandle theAlias, HFSFlavor *theFlavor);
  54.  
  55. /* IconsToMaskedPixMap converts either an IconServices icon reference or a IconUtilities icon suite into a
  56.     (GWorldPtr, RgnHandle) pair appropriate for dragging as a transparent icon image.  if iconReference
  57.     then calls to IconServices are made, if iconSuite is not null, then calls to icon services are made. 
  58.     The resulting graphics world and region handle are returned in *imageGWorld and *maskRgn. */
  59. OSErr IconsToMaskedPixMap(const Rect *iconRect, Handle iconSuite, IconRef iconReference,
  60.                     GWorldPtr *imageGWorld, RgnHandle *maskRgn);
  61.  
  62.  
  63. /* GrayOutBox grays out an area of the screen in the current grafport.  
  64.     *theBox is in local coordinates in the current grafport. This routine
  65.     is for direct screen drawing only.  */
  66. void GrayOutBox(Rect *theBox);
  67.  
  68.  
  69. /* ShowDragHiliteBox is called to hilite the drop box area in the
  70.     main window.  Here, we draw a 3 pixel wide border around *boxBounds.  */
  71. OSErr ShowDragHiliteBox(DragReference theDragRef, Rect *boxBounds);
  72.  
  73.  
  74. /* CopyFileCmd starts a thread manager background task to copy a file.  parameters specify
  75.     the files to copy, and callbacks made to the caller during the copy operation.  It is not
  76.     re-entrant.  */
  77. enum {
  78.         /* codes passed in the message parameter to the callback routine passed
  79.         to the CopyFileCmd routine.  */
  80.     kCopyStart, /* called at the beginning of the copy operation */
  81.     kCopyRun, /* called during the copy operation. */
  82.     kCopyEnd,/* called at the end of the copy operation (including when it aborts or on error) */
  83.         /* error code indicating returned if an attempt is made to copy a directory */
  84.     kCannotCopyDirError = 2335,
  85.     kCopyNotRentrantError = 2336, /* only one copy at a time */
  86.     kCopyBufferSize = (16*1024) /* size of the io buffer for file copies */
  87.         /* we use a smaller buffer so the probability of the progress box
  88.         showing up is improved. */
  89. };
  90.  
  91.     /* called back periodically durring the copy operation.  This routine provides
  92.     opportunity for the caller to display feedback for the copy operation.  theFile
  93.     is the source file being copied, message will be one of the codes defined above,
  94.     and percentComplete indicates the percentage of the operation that has been completed. */
  95. typedef void (*CopyCallback)(FSSpec *theFile, short message, long percentCompleted);
  96.  
  97.     /* called back back if an error occurs during the copy operation. 
  98.     theFile specifies the source file name, errorCode specifies the error causing
  99.     the abort.  if AbortCopyOperation is called, errorCode will be userCanceledErr.  */
  100. typedef void (*CopyErrorHandler)(FSSpec *theFile, short errorCode);
  101.  
  102. /* CopyFileCmd starts a copy command copying the source file to the target file.  This routine
  103.     assumes that the target file has been created.  If the copy fails, the target file
  104.     will be deleted.  the callback and the errorhandler are called as appropriate during the operation. */
  105. OSErr CopyFileCmd(FSSpec *theSource, FSSpec *theTarget, CopyCallback callback, CopyErrorHandler errorhandler);
  106.  
  107. /* AbortCopyOperation aborts the copy operation. All structures allocated are disposed,
  108.     files opened are closed, and any files created are deleted. */
  109. void AbortCopyOperation(void);
  110.  
  111. /* CopyFileInProgress returns true while a copy operation is in progress */
  112. Boolean CopyFileInProgress(void);
  113.  
  114. #endif
  115.